package com.wit.WEB.controller;

import com.wit.WEB.entity.User;
import com.wit.WEB.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.HtmlUtils;

import javax.servlet.http.HttpSession;

/**
 * @program: WEB
 * @description: 前端控制器
 * @author: KingTeng
 * @create: 2022-02-23 20:08
 **/
@RestController
public class ForeRestController {

    private  UserService userService;
    @Autowired
    private  void  setUserService(UserService userService){this.userService=userService;};

    @PostMapping("/foreLogin")
    public String login(String name, String pwd, HttpSession session) {
        User user = userService.selectByAcAndPW(HtmlUtils.htmlEscape(name), pwd);
        if (user == null) {
            return  "fail";
        }
        session.setAttribute("user", user);
        return "success";
    }

}
